import Taro, { Component } from '@tarojs/taro'
import { View , Text , Image , RichText} from '@tarojs/components';
import { baseImgSrc } from '../../util/base_url';
import { AtAccordion  } from 'taro-ui';
import { getAns } from '../../util/api';
import './question.scss';
export default class Question extends Component{
    config = {
        navigationBarTitleText:"安全中心",
    }
    constructor(){
        super(...arguments);
        this.state = {
            open:false,
            list:[],
        }
    }
    componentWillMount(){
        getAns({cat_id:2}).then(res => {
            console.log(res)
            if(res.code == 0){
                this.setState({list:res.list.map(v => Object.assign(v,{status:false}))});
            }
        })
    }
    handleClick(idx){
        let { list } = this.state;
        list[idx].status = !list[idx].status;
        this.setState({list}) 
    }
    render(){
        let { list } = this.state;
        return(
            <View className='question'>
                {
                   list.map( (v,i) => (
                    <View className='qu-item'>
                        <AtAccordion
                            open={v.status}
                            onClick={this.handleClick.bind(this,i)}
                            title={v.title}
                        >
                            <View className='ans'><RichText nodes={v.content} /></View>
                        </AtAccordion>
                    </View>
                   ))
                }
            </View>
        )
    }
}